package com.nut.course.api.biz;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nut.course.api.req.CourseOrderReq;
import com.nut.course.common.Constants;
import com.nut.course.common.Holder;
import com.nut.course.common.Result;
import com.nut.course.entity.CourseOrder;
import com.nut.course.interceptor.UserJwt;
import com.nut.course.service.CourseOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//学校端 查看课程订单
@Slf4j
@RestController
@RequestMapping("/schoolOrder")
public class SchoolOrderController {

    @Autowired
    private CourseOrderService courseOrderService;

    //课程订单分页列表
    @GetMapping("list")
    public Result<IPage<CourseOrder>> list(
            @RequestParam Integer partnerId,
            @RequestParam String status,
            @RequestParam String name,
            @RequestParam(defaultValue = "1") Integer pageNo,
            @RequestParam(defaultValue = "10") Integer pageSize) {

        return courseOrderService.list(Constants.DEFAULT_SCHOOL_ID, partnerId, status, name, pageNo, pageSize);
    }

    @GetMapping(value = "/{id}")
    public Result<CourseOrder> detail(@PathVariable Integer id) {
        return courseOrderService.getById(id);
    }

    //学校老师提交 课程订单
    @PostMapping(value = "submit")
    public Result submit(@RequestBody CourseOrderReq courseOrderReq) {

        UserJwt userJwt = Holder.USER_JWT_THREAD_LOCAL.get();
        log.info("userId=" + userJwt.getUserId());

        return courseOrderService.submit(userJwt, courseOrderReq);
    }
}
